<?php

namespace App\Http\Controllers\Auth;

use App\Models\User;
use App\Models\LoginTime;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Facades\JWTAuth;
use App\Http\Controllers\Controller;

class Login extends Controller
{
    public function login (Request $request)
    {
        $credentials = $request->only ('job_number', 'password');
        if (!$token = \Auth::guard ('api')->attempt ($credentials)) {
            return $this->error ("用户名密码错误");
        } else {
          $user =   User::query ()->where ("job_number",$credentials["job_number"])->first  ();
           $data = [
               "expire_time" => time () + 7200,
               "user" => $user
           ];
            $data =   base64_encode (json_encode ($data));
            return $this->success ($data, "登陆成功");
        }
    }

    public function  logout(Request $request)
    {
        @\Auth::guard('api')->logout();
        return $this->success ("","退出成功");
    }
    public function  info(Request $request)
    {
        dd (auth ('api')->user ());
    }
}
